//
//  ChengJiYiChangCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/6/13.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "ChengJiYiChangCell.h"

@implementation ChengJiYiChangCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
    }
    return self;
}
- (void)initSubView{
    UILabel *contLab = [UILabel new];
    CGFloat W = 1.0/6;
    NSArray *array = @[@"学生",@"学号",@"考试次数",@"上升名次",@"操作"];
    for (int i = 0; i<5; i++) {
        if (i == 0) {
            UILabel *label = [[UILabel alloc]init];
            label.textAlignment = 1;
            label.textColor = TITLECOLOR;
            label.font = [UIFont systemFontOfSize:15];
            label.text = array[i];
            [self addSubview:label];
            label.tag = 20+i;
            contLab = label;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(@0);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
        } else if(i==4){
            UIView *label = [[UIView alloc]init];
            [self addSubview:label];
            label.tag = 20+i;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contLab.mas_right);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W*2);
                make.height.mas_equalTo(40);
            }];
            _caoZuoView = label;
            [_caoZuoView addSubview:self.buttonView];
            [_buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(label.mas_left);
                make.top.equalTo(label.mas_top);
                make.right.equalTo(label.mas_right);
                make.bottom.equalTo(label.mas_bottom);
            }];
        }else{
            UILabel *label = [[UILabel alloc]init];
            label.textAlignment = 1;
            label.textColor = TITLECOLOR;
            label.font = [UIFont systemFontOfSize:15];
            label.text = array[i];
            [self addSubview:label];
            label.tag = 20+i;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contLab.mas_right);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
            contLab = label;
        }
    }
    
}
- (void)reloadViewArray:(NSArray *)array{
    for (int i =0;i<array.count;i++) {
        UILabel *label = (UILabel *)[self viewWithTag:20+i];
        label.text = array[i];
    }
}
- (CJYButtonView *)buttonView{
    if (!_buttonView) {
        CGFloat W = self.frame.size.width/6.0;
        CJYButtonView *view = [[CJYButtonView alloc]initWithFrame:CGRectMake(0, 0, W*2, 50)];
        view.index = self.index;
        _buttonView = view;
    }
    return _buttonView;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)drawRect:(CGRect)rect{
    UIBezierPath *path = [[UIBezierPath alloc]init];
    [path moveToPoint:CGPointMake(0,50)];
    [path addLineToPoint:CGPointMake(self.frame.size.width, 50)];
    [LINCOLOR set];
    [path stroke];
    CGFloat W = self.frame.size.width/6.0;
    for (int i = 1; i<5; i++) {
        UIBezierPath *pathNext =[[UIBezierPath alloc]init];
        [pathNext moveToPoint:CGPointMake(W*i,0)];
        [pathNext addLineToPoint:CGPointMake(W*i, 50)];
        [LINCOLOR set];
        [pathNext stroke];
    }
}
@end
